home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Today - The Disc! 5 / CD-ROM Today - The Disc (Issue 5)(November 1994).ISO / mac / Mac shareware / Education / RLaB / examples / plot_test.r < prev    next >
Encoding:
Text File  |  1994-09-21  |  3.4 KB  |  185 lines  |  [TEXT/ttxt]

  1. #
  2. # Test 2-D plots
  3. #
  4.  
  5. pstart ();
  6. x = (0.25:4:.25)';
  7.  
  8. ptitle ("Multiple Line Colors and Styles");
  9. xlabel ("X-axis Label");
  10. ylabel ("Y-axis Label");
  11. plot ( [x, x, 2*x, 3*x] );
  12. pause ("Type RETURN to continue");
  13.  
  14. ptitle ("Multiple Point Colors and Styles");
  15. plstyle ("point");
  16. plot ( [x, x, 2*x, 3*x] );
  17. pause ("Type RETURN to continue");
  18.  
  19. # Start a new window with multiple plots
  20. pstart(2,2);
  21.  
  22. # Show off Grid Styles
  23. ptitle("Plot 1, No Grid");
  24. plgrid ("", "");
  25. plot ([x,exp(-x*0.5)]);
  26.  
  27. ptitle("Plot 2, Grid Box Only");
  28. plgrid ("bc", "bcv");
  29. plot ([x,2*x,3*x,4*x]);
  30.  
  31. ptitle("Plot 3, Box, and Coordinates");
  32. plgrid ("bcnt", "bcnvt");
  33. plot ([x,-2*x,2*x]);
  34.  
  35. ptitle("Plot 4, ");
  36. plgrid ("bcngst", "bcngvst");
  37. plot ([x,x,cos(2*pi*x*0.25)]);
  38. pause ("Type RETURN to continue");
  39.  
  40. # Show off axis types
  41. ptitle("Linear Axes");
  42. plgrid();
  43. plot ([x,exp(-x*0.5)]);
  44.  
  45. ptitle("Log X - Axis");
  46. plgrid("bcngstl");
  47. plot ([x,exp(-x*0.5)]);
  48.  
  49. ptitle("Log Y - Axis");
  50. plgrid("bcngst", "bcngstlv");
  51. plot ([x,exp(-x*0.5)]);
  52.  
  53. ptitle("Log  Axes");
  54. plgrid("bcngstl", "bcngstlv");
  55. plot ([x,exp(-x*0.5)]);
  56. pause ("Type RETURN to continue");
  57.  
  58. pstart();
  59.  
  60. # Data with different scales
  61. y = (0.5:6:.2)';
  62. ptitle("Plot Data with Different Scales");
  63. plot (<< [x,exp(-x*0.5)] ; [y, exp (y*0.25), exp(y*0.1)] >>);
  64. pause ("Type RETURN to continue");
  65.  
  66. # Histograms
  67.  
  68. rand("normal", 0, pi);
  69. r = rand(2000,1);
  70.  
  71. ptitle("Histogram, Default No. of Bins");
  72. plhist (r);
  73. pause ("Type RETURN to continue");
  74.  
  75. ptitle("Histogram, 30 Bins");
  76. plhist (r, 30);
  77. pause ("Type RETURN to continue");
  78.  
  79. # Make 3D data
  80.  
  81. # Sombrero
  82.  
  83. NX = 20;
  84. NY = 20;
  85. xx = zeros (1, NX);
  86. yy = zeros (1, NY);
  87. for (i in 1:NX) { xx[i] = (i - NX/2)/(NX/2); }
  88. for (i in 1:NY) { yy[i] = (i - NY/2)/(NY/2); }
  89.  
  90. zz = zeros (NX, NY);
  91.  
  92. for (i in 1:NX)
  93. {
  94.   for (j in 1:NY)
  95.   {
  96.     r = sqrt (xx[i]^2 + yy[j]^2);
  97.     zz[i;j] = exp (-r * r) * cos (2*pi*r);
  98.   }
  99. }
  100.  
  101. # Now create some plots
  102.  
  103. ptitle("3-D Plot, Sombrero");
  104. plmesh (<< x = xx; y = yy; z = zz>>);
  105. pause ("Type RETURN to continue");
  106.  
  107. # Sin - Cos surface
  108.  
  109. x1 = -3:3:.2;
  110. y1 = -3:3:.2;
  111. z1 = zeros (x1.n, y1.n);
  112.  
  113. for (i in 1:x1.n)
  114. {
  115.   for(j in 1:y1.n)
  116.   {
  117.     z1[i;j] = sin(y1[j]) * cos(x1[i]);
  118.   }
  119. }
  120.  
  121. ptitle("3-D Plot, Cos-Sine Surface");
  122. plmesh (<< x = x1; y = y1; z = z1>>);
  123. pause ("Type RETURN to continue");
  124.  
  125. # Slanted plane
  126.  
  127. x2 = 1:10;
  128. y2 = 1:10;
  129. z2 = zeros (x2.n, y2.n);
  130. for (i in 1:x2.n) { z2[i;] = i*ones(1,y2.n); }
  131.  
  132. ptitle("3-D Plot, Plane");
  133. plmesh (<< x = x2; y = y2; z = z2>>);
  134. pause ("Type RETURN to continue");
  135.  
  136. # Two Slanted planes
  137. z3 = -2*z2;
  138. ptitle("3-D Plot, 2 - Planes");
  139. plmesh (<< x = x2; y = y2; z = z2>>, <<x = x2; y = y2; z = z3 >>);
  140.  
  141. # Exponential Surface (sort-of)
  142.  
  143. x4 = -2:2:.2;
  144. y4 = x4;
  145. z4 = [];
  146. for (i in 1:x4.n) { 
  147.   for (j in 1:y4.n) { 
  148.     z4[i;j] = x4[i] * exp (-x4[i]^2 - y4[j]^2);
  149.   }
  150. }
  151. ptitle ("Neat Surface");
  152. plmesh (<<x=x4;y=y4;z=z4>>);
  153.  
  154. # Now show 3-D viewing angles
  155.  
  156. # Switch back to 2-by-2 window
  157. pwin(1);
  158. "Focus on 2nd window"
  159. pause ("Type RETURN to continue");
  160.  
  161. ptitle("3-D Plot, Sombrero, Default View, Alt = 60, Az = 45");
  162. plmesh (<< x = xx; y = yy; z = zz>>);
  163.  
  164. ptitle("3-D Plot, Sombrero, Alt = 10, Az = 10");
  165. plalt(10); 
  166. plaz(10);
  167. plmesh (<< x = xx; y = yy; z = zz>>);
  168.  
  169. ptitle("3-D Plot, Sombrero, Alt = 20, Az = 30");
  170. plalt(20); 
  171. plaz(30);
  172. plmesh (<< x = xx; y = yy; z = zz>>);
  173.  
  174. ptitle("3-D Plot, Sombrero, Alt = 80, Az = 60");
  175. plalt(80); 
  176. plaz(60);
  177. plmesh (<< x = xx; y = yy; z = zz>>);
  178.  
  179. ans = input ("Replot (y/n) ?:", "s");
  180. if (ans == "y" || ans == "Y") { replot(); }
  181.  
  182. pause ("Type RETURN to END");
  183.  
  184. pend();
  185.